package vn.lumi.smarthome.ulti;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;

public class Preference {
	private static final String PREFERENCES_NAME = "prefers_smarthome";

	@SuppressLint("CommitPrefEdits")
	private static SharedPreferences.Editor getEditor(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				PREFERENCES_NAME, Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = sharedPreferences.edit();
		return editor;
	}

	private static SharedPreferences getPreferences(Context context) {
		return context.getSharedPreferences(PREFERENCES_NAME,
				Context.MODE_PRIVATE);
	}

	public static void saveRemember(Context context, boolean value) {
		getEditor(context).putBoolean("isRemember", value).commit();
	}

	public static boolean isRemember(Context context) {
		return getPreferences(context).getBoolean("isRemember", false);
	}

	public static void saveUID(Context context, String uid) {
		getEditor(context).putString("uid", uid).commit();
	}

	public static String getUID(Context context) {
		return getPreferences(context).getString("uid", "");
	}
	
	

	public static void saveVibrate(Context context, boolean isVibrate) {
		getEditor(context).putBoolean("vibrate", isVibrate).commit();
	}

	public static boolean getVibrate(Context context) {
		return getPreferences(context).getBoolean("vibrate", false);
	}

	public static void saveVibratePr(Context context, boolean isVibrate) {
		getEditor(context).putBoolean("vibratePr", isVibrate).commit();
	}

	public static boolean getVibratePr(Context context) {
		return getPreferences(context).getBoolean("vibratePr", false);
	}

	/**
	 * @param context
	 * @param language
	 *            :  2- Viet Nam, 3- English
	 */
	public static void saveLanguage(Context context, int language) {
		getEditor(context).putInt("language", language).commit();
	}

	/**
	 * @param context
	 * @return  2- Viet Nam, 3- English
	 */
	public static int getLanguage(Context context) {
		return getPreferences(context).getInt("language", 1);
	}

//	public static void saveDefaultLanguage(Context context, String language) {
//		getEditor(context).putString("languageDefault", language).commit();
//	}
//
//	public static String getDefaultLanguage(Context context) {
//		return getPreferences(context).getString("languageDefault", "en");
//	}

	public static void savepwd(Context context, String pwd) {
		getEditor(context).putString("pwd", pwd).commit();
	}

	public static String getPWD(Context context) {
		return getPreferences(context).getString("pwd", "");
	}

	public static String getLAN_IP(Context context) {
		return getPreferences(context).getString("LAN_IP", "");
	}

	public static void saveLAN_IP(Context context, String ip) {
		getEditor(context).putString("LAN_IP", ip).commit();
	}

	public static int getLAN_port(Context context) {
		return getPreferences(context).getInt("LAN_port", 0);
	}

	public static void saveLAN_port(Context context, int port) {
		getEditor(context).putInt("LAN_port", port).commit();
	}

	public static String getDNS_Address(Context context) {
		// return getPreferences(context).getString("DNS_Address",
		// "lumi.dlinkddns.com");
		return getPreferences(context).getString("DNS_Address", "");
	}

	public static void saveDNS_Address(Context context, String ip) {
		getEditor(context).putString("DNS_Address", ip).commit();
	}

	public static int getDNS_port(Context context) {
		return getPreferences(context).getInt("DNS_port", 0);
	}

	public static void saveDNS_port(Context context, int port) {
		getEditor(context).putInt("DNS_port", port).commit();
	}

	public static int getConfigVersion(Context context) {
		return getPreferences(context).getInt("Config Version", 0);
	}

	public static void saveConfigVersion(Context context, int config) {
		getEditor(context).putInt("Config Version", config).commit();
	}
}
